package com.ruoyi.web.controller.cs;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.controller.BasicsController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.Response;
import com.ruoyi.common.core.page.ResponsePageInfo;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.Excel2Util;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cs.domain.TRedbag;
import com.ruoyi.cs.domain.TRedbagOpen;
import com.ruoyi.cs.service.ITRedbagOpenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 红包开启记录Controller
 * 
 * @author ruoyi
 * @date 2021-03-25
 */
@Api(tags = "红包开启记录")
@RestController
@RequestMapping("/buff/redbagopen")
public class TRedbagOpenController extends BasicsController
{
    @Autowired
    private ITRedbagOpenService tRedbagOpenService;

    /**
     * 查询红包开启记录列表
     */
    @ApiOperation("查询红包开启记录列表")
    @PreAuthorize("@ss.hasPermi('system:open:list')")
    @GetMapping("/list")
    public ResponsePageInfo<TRedbagOpen> list(TRedbagOpen tRedbagOpen)
    {
        startPage();
        List<TRedbagOpen> list = tRedbagOpenService.selectTRedbagOpenList(tRedbagOpen);
        return toResponsePageInfo(list);
    }

    /**
     * 导出红包开启记录列表
     */
    @ApiOperation("导出红包开启记录列表")
    @PreAuthorize("@ss.hasPermi('system:open:export')")
    @Log(title = "红包开启记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public Response<String> export(TRedbagOpen tRedbagOpen)
    {
        List<TRedbagOpen> list = tRedbagOpenService.selectTRedbagOpenList(tRedbagOpen);
        Excel2Util<TRedbagOpen> util = new Excel2Util<TRedbagOpen>(TRedbagOpen.class);
        return util.exportExcel(list, "open");
    }

    /**
     * 获取红包开启记录详细信息
     */
    @ApiOperation("获取红包开启记录详细信息")
    @PreAuthorize("@ss.hasPermi('system:open:query')")
    @GetMapping(value = "/{redbagKqId}")
    @ApiImplicitParam(name = "redbagKqId",value = "红包开启记录ID" , dataType = "String", paramType = "query", required = true)
    public Response<TRedbagOpen> getInfo(@PathVariable("redbagKqId") String redbagKqId)
    {
        return Response.success(tRedbagOpenService.selectTRedbagOpenById(redbagKqId));
    }

    /**
     * 新增红包开启记录
     */
    @ApiOperation("新增红包开启记录")
    @PreAuthorize("@ss.hasPermi('system:open:add')")
    @Log(title = "红包开启记录", businessType = BusinessType.INSERT)
    @PostMapping
    public Response<Integer> add(@RequestBody TRedbagOpen tRedbagOpen)
    {
        return toResponse(tRedbagOpenService.insertTRedbagOpen(tRedbagOpen));
    }

    /**
     * 修改红包开启记录
     */
    @ApiOperation("修改红包开启记录")
    @PreAuthorize("@ss.hasPermi('system:open:edit')")
    @Log(title = "红包开启记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public Response<Integer> edit(@RequestBody TRedbagOpen tRedbagOpen)
    {
        return toResponse(tRedbagOpenService.updateTRedbagOpen(tRedbagOpen));
    }

    /**
     * 删除红包开启记录
     */
    @ApiOperation("删除红包开启记录")
    @PreAuthorize("@ss.hasPermi('system:open:remove')")
    @Log(title = "红包开启记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{redbagKqIds}")
    @ApiImplicitParam(name = "redbagKqIds",value = "需要删除的红包开启记录ID,数组" , dataType = "String[]", paramType = "query", required = true)
    public Response<Integer> remove(@PathVariable String[] redbagKqIds)
    {
        return toResponse(tRedbagOpenService.deleteTRedbagOpenByIds(redbagKqIds));
    }
}
